<template>
	<view class="container-gray">
		<view v-if="dataList.length">
			<view class="head" v-for="(item,index) in dataList" :key="index" @click="goExamination(item.examId)">
				<view class="exam-title">{{item.examName}}</view>
				<view class="info-text">{{item.submitPaperTime}}，分数{{item.score}}分</view>
			</view>
		</view>
		<view v-else class="tips">暂无考试记录</view>
	</view>
</template>

<script>
	import {
		post_md5
	} from './../../common/request'
	import {
		setNavTitle
	} from './../../common/common'

	export default {
		data() {
			return {
				dataList: [],
				page: 1,
				type: null
			}
		},
		onLoad(options) {
			let title = ''
			this.type = options.examType
		},
		onShow() {
			switch (parseInt(this.type)) {
				case 1:
					setNavTitle('正式考试')
					break;
				case 2:
					setNavTitle('模拟考试')
					break;
				default:
					setNavTitle('三违考试')
					break;
			}
			this.getList(this.type)
			this.dataList = []
		},
		onReachBottom() {
			this.page++
			this.getList(this.type)
		},
		methods: {
			// 获取对应分类的考试记录
			getList(type) {
				const params = {
					userId: uni.getStorageSync('userId'),
					examType: parseInt(type),
					page: this.page,
					limit: 20
				}
				post_md5('/exam-app/exam/userexamrecord', params).then(res => {
					if (res.data) this.dataList = this.dataList.concat(res.data.list)
				})
			},
			// 查看考試結果
			goExamination(id) {
				uni.navigateTo({
					url: '../recording/examination-result?id=' + id + '&annal=true'
				})
			}
		}
	}
</script>

<style>
	.head {
		border: none;
		margin-bottom: 0;
		padding: 20upx 40upx;
		margin-top: 1px;
	}

	.exam-title {
		font-size: 30upx;
		color: #333333;
		font-weight: 600;
	}

	.info-text {
		font-size: 24upx;
		color: #999999;
		margin-top: 18upx;
	}

	.tips {
		color: #999999;
		text-align: center;
		margin-top: 100upx;
	}
</style>
